package action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import bean.UserBean;

public class User {
	
	public String getUserInfoFromDb(String userId, Connection conn){
		String sql = "SELECT * FROM user WHERE accountid=?";

		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, userId);
			rs = stmt.executeQuery();
			if(rs.next()){
				UserBean bean = new UserBean();
				bean.setId(rs.getInt("id"));
				bean.setUserName(rs.getString("username"));
				bean.setFirstName(rs.getString("firstname"));
				bean.setLastName(rs.getString("lastname"));
				bean.setSex(rs.getInt("sex"));
				bean.setPhone(rs.getString("phone"));
				bean.setCityId(rs.getString("cityid"));
				bean.setCountryId(rs.getString("countryid"));
				bean.setAddress(rs.getString("address"));
				return bean.toString();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try {if (rs != null) rs.close();}catch (Exception e) {}
			try {if (stmt != null) stmt.close();}catch (Exception e) {}
		}
		return null;
	}
}
